<template>
  <div id="app">
    <el-upload
      action="http://119.91.217.109:8887/upload"
      list-type="picture-card"
      :auto-upload="false"
      ref="uploadRef"
      :file-list="fileList"
      :on-success="test"
      multiple
    >
      <i slot="default" class="el-icon-plus"></i>
      <div slot="file" slot-scope="{ file }">
        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="" />
        <span class="el-upload-list__item-actions">
          <span
            class="el-upload-list__item-preview"
            @click="handlePictureCardPreview(file)"
          >
            <i class="el-icon-zoom-in"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleDownload(file)"
          >
            <i class="el-icon-download"></i>
          </span>
          <span
            v-if="!disabled"
            class="el-upload-list__item-delete"
            @click="handleRemove(file)"
          >
            <i class="el-icon-delete"></i>
          </span>
        </span>
      </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="" />
    </el-dialog>

    <div class="demo-image__lazy">
      <el-image v-for="url in shunxu" :key="url" :src="url" lazy></el-image>
    </div>
    <el-button
      style="margin-left: 10px"
      size="small"
      type="success"
      @click="submitUpload"
      >上传到服务器</el-button
    ><el-button
      style="margin-left: 10px"
      size="small"
      type="success"
      @click="quanxin"
      >上传到服务器</el-button
    >
    <el-button
      style="margin-left: 10px"
      size="small"
      type="success"
      @click="quanxin1"
      >显示</el-button
    >

    <pre>{{ resList }}</pre>
    <pre>{{ sizeList }}</pre>
    <pre>{{ shunxu }}</pre>
    <pre>{{ fileList }}</pre>
  </div>
</template>

<script>
export default {
  data() {
    return {
      fileList: [],
      dialogImageUrl: "",
      dialogVisible: false,
      disabled: false,
      sizeList: [],
      resList: [],
      shunxu: [],
    };
  },
  methods: {
    test(res, file, fileList) {
      this.resList.unshift(res);
      this.sizeList.unshift(file.size);
      this.fileList = fileList;
    },
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    },
    submitUpload() {
      this.$refs.uploadRef.submit();
    },
    quanxin() {
      this.sizeList.forEach((itme, index) => {
        console.log(index);
        console.log(itme);
        console.log(this.resList);
        console.log(this.resList[index][1]);
        if (itme == this.resList[index][1]) {
          this.shunxu.push(
            `http://119.91.217.109:8887/${this.resList[index][0]}.jpg`
          );
        }
      });
    },
    quanxin1() {
      this.fileList.forEach((itme) => {
        for (let i = 0; i < this.fileList.length; i++) {
          if (itme.size == this.resList[i][1]) {
            this.shunxu.push(
              `http://119.91.217.109:8887/${this.resList[i][0]}.jpg`
            );
          }
        }
      });
    },
  },
};
</script>

<style>
</style>
